#!!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
"""

def auto_login_baiduHi(url, name, passwd):
    import urllib, urllib2, httplib, cookielib

    url_hi = "http://passport.baidu.com/?login"

    cookie = cookielib.CookieJar()
    cj = urllib2.HTTPCookieProcessor(cookie)

    postdata = urllib.urlencode({'username':name, 'password':passwd})
    request = urllib2.Request(url_hi, postdata)

    proxy = urllib2.ProxyHandler({'http': 'http://huys-office.3322.org:9928/'})

    opener = urllib2.build_opener(cj, proxy)

    f = opener.open(request)

    print f

    hi_html = opener.open(url)

    return hi_html

###
if __name__=="__main__":
    from httplib import HTTPConnection

    h = HTTPConnection('www.tsinghua.edu.cn')
    print h

    h.connect()

    h.request("GET", "/index.html")

    r = h.getresponse()

    print r.status, r.reason

    print r.getheaders()

    print r.msg

    print r.version

    print r.length

    data = r.read()

    print data

    h.close()

    hi = auto_login_baiduHi(url='http://hi.baidu.com/fox000002', name = 'fox000002', passwd = '090200')

    fout = open('hi.html', 'w')
    print >>fout, hi.read()

    raw_input("Press any key to continute...")
